package com.woniuxy.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 */
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseData<?> sysException(Exception e){
        e.printStackTrace();//把异常信息打印到控制台
        if(e instanceof IllegalAccessException){
            //返回参数异常
            return new ResponseData<>().fail(ResponseEnum.PARAM_ERROR);
        }else {
            //返回通用异常
            return new ResponseData<>().fail(ResponseEnum.FAIL);
        }
    }
}
